<?php defined("MAIN_DIR") or die("No direct access");

to("/$current_city[path]/banks");

$bank_id = trim(strip_tags($route->getPath(4)));
$box_query = "select `Bx`.*,`B`.`link`,`B`.`name`,`B`.`city_id` from `box` as `Bx`,`bank` as `B` where `Bx`.`bank_id` = '$bank_id' and `Bx`.`bank_id` = `B`.`bank_id`";
$box_res = mysql_query($box_query);
if ($count = mysql_num_rows($box_res) == 0) {
	to("/$c_name/banks/boxes");
}

$limit = 5;
$page = 1;
if (isset($_GET['page']))
	$page = $_GET['page'];
$max_page = ceil($count/$limit);
if ($max_page == 0)
	$max_page++;
if ($page > $max_page)
	$page = $max_page;
elseif ($page < 1)
	$page = 1;
$start_list = (ceil($page)-1)*$limit;
$box_query .= " limit $start_list,$limit";
$box_res = mysql_query($box_query);
$box_count = mysql_num_rows($box_res);

$box_row = mysql_fetch_array($box_res);
$bank_city = mysql_fetch_array(mysql_query("select * from `city` where `city_id` = '$box_row[city_id]' limit 1"));
$head_title = "Аренда сейфовых ячеек в ".$box_row['name']." в ".$bank_city['city_name_rod'];
$head_description = "Стоимость аренды сейфов в банке «".$box_row['name']."» в ".$bank_city['city_name_pred'];
$head_keywords = "сейфовая ячейка аренда сейф ".$box_row['name']." ".$bank_city['city_name'];
mysql_data_seek($box_res,0);

if ($_SESSION['city'] != $box_row['city_id']) {
	to("/$bank_city[path]/banks/boxes/$box_row[bank_id]");
}

require_once APP.HEADFILE;
?>
<script type="text/javascript" src="/files/js/bank_list.js"></script>
<h1>Сейфовые ячейки в <?php echo $current_city['city_name_pred']; ?></h1>
<div id="rko_table"><?php
	while ($box_row = mysql_fetch_array($box_res))
	{
		$days = explode(",",$box_row['days']);
		$dimensions = explode(",",$box_row['dimensions']);
		$cost = explode(",",$box_row['cost']);
		
		$days_count = count($days);
		$dimensions_count = count($dimensions);
		if ($days_count > 2)
			$width = 800/($days_count+1);
		else
			$width = 800/($days_count+2);
		
		?><table width="990px" border="0" cellspacing="0" cellpadding="12">
			<tr>
				<td colspan="<?php
				$colspan = $days_count+1;
				if ($days_count < 3) $colspan++;
				if ($days_count == 2) $colspan++;
				echo $colspan;
				?>" align="left">
					<div class="seify_bank"><a href="<?php echo "/$c_name";?>/banks/<?php echo $box_row['link'].".html"; ?>"><?php echo $box_row['name']; ?></a>
					&nbsp;&nbsp;&nbsp;<?php echo $box_row['address']; ?>, тел.: <?php echo $box_row['phone']; ?></div>
				</td>
			</tr>
			<tr>
				<td width="190px" align="left">&nbsp;</td>
				<td <?php if ($days_count > 2) echo "colspan='2'"; else echo "width='210px'"; ?> align="left" bgcolor="#a3a3a3" class="seify_legenda_white rko_left_border">Стоимость аренды, руб. в день</td><?php
				for ($i = 0; $i < $days_count-2; $i++)
					echo "<td align='left'>&nbsp;</td>";
				if ($days_count < 3)
					echo "<td align='left'>&nbsp;</td>";
				if ($days_count == 2)
					echo "<td align='left'>&nbsp;</td>";
			?></tr>
			<tr>
				<td align="left" bgcolor="#FFFFFF">Размеры<div class="seify_legenda_grey">ширина x глубина x высота (см)</div></td><?php
				for ($i = 0; $i < $days_count; $i++)
				{
					echo "<td ";
					if ($days_count > 1)
						echo "width='$width px'";
					echo "align='left' bgcolor='#FFFFFF'";
					echo ($i == 0) ? "class='rko_left_border'" : "";
					echo ">$days[$i]</td>";
				}
				if ($days_count < 3)
					echo "<td align='left'>&nbsp;</td>";
			?></tr><?php
			$cost_count = 0;
			for ($i = 0; $i < $dimensions_count; $i++)
			{
				?><tr>
					<td align="left"><?php echo $dimensions[$i]; ?></td><?php
					for ($j = 0; $j < $days_count; $j++)
					{
						echo "<td align='left'";
						echo ($j == 0) ? "class='rko_left_border'" : "";
						echo ">".$cost[$cost_count++]."</td>";
					}
					if ($days_count < 3)
						echo "<td align='left'>&nbsp;</td>";
				?></tr><?php
			}
		?></table>
		<div style="clear:both">&nbsp;</div><?php
	}
?></div>
<div class="inside_block">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr valign='top'>
			<td width="344" class="inside_info"><?php
				require_once APP."bank_list.php";
				require_once APP."currency_rates.php";
			?></td>
			<td width="646"><?php
				$info = mysql_fetch_array(mysql_query("select * from `info` where `info_id` = '2' limit 1"));
				$text = getRichText($info['text']);
				echo "<h2>$info[header]</h2>";
				echo "<p>$text</p>";
			?></td>
		</tr>
	</table>
</div>
<?php require_once APP.FOOTERFILE; ?>